package zpy.servlet.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Servlet implementation class NetInformationServlet
 */
@WebServlet("/NetInformationServlet")
public class NetInformationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NetInformationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String getRemoteAddr       = request.getRemoteAddr();
		String getRemoteHost   = request.getRemoteHost();
		int getRemotePort  = request.getRemotePort();
		String getLocalAddr     = request.getLocalAddr();
		String getLocalName  = request.getLocalName();
		int getLocalPort  = request.getLocalPort();
		String getServerName  = request.getServerName();
		int getServerPort  = request.getServerPort();
		String getScheme  = request.getScheme();
		String getRequestURL  = request.getRequestURL().toString();
		request.setAttribute("getRemoteAddr", getRemoteAddr);
		request.setAttribute("getRemoteHost", getRemoteHost);
		request.setAttribute("getRemotePort", getRemotePort);
		request.setAttribute("getLocalAddr", getLocalAddr);
		request.setAttribute("getLocalName", getLocalName);
		request.setAttribute("getLocalPort", getLocalPort);
		request.setAttribute("getServerName", getServerName);
		request.setAttribute("getServerPort", getServerPort);
		request.setAttribute("getScheme", getScheme);
		request.setAttribute("getRequestURL", getRequestURL);
		
		getServletContext().getRequestDispatcher("/WEB-INF/jsp/threeChapt/net_information.jsp")
		.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
